<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <span>{{ userName }}</span>
      <Icon :size="18"
            type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
import './user.less'
import { setToken } from '@/libs/util'
export default {
  name: 'User',
  props: {
    userName: {
      type: String,
      default: ''
    },
    userAvator: {
      type: String,
      default: ''
    }
  },
  methods: {
    handleClick (name) {
      switch (name) {
        case 'logout':
          localStorage.removeItem('userId')
          localStorage.removeItem('userName')
          localStorage.removeItem('userAccess')
          localStorage.removeItem('userAccessMenu')
          setToken('')
          this.$router.push({
            name: 'login'
          })
          break
      }
    }
  }
}
</script>
